/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.samuelwall.materialtaptargetprompt.sample;

import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.ScrollView;
import ohos.agp.components.Text;
import ohos.agp.components.element.VectorElement;
import ohos.agp.text.Font;
import ohos.agp.window.service.WindowManager;
import ohos.global.resource.NotExistException;
import ohos.global.resource.ResourceManager;
import ohos.global.resource.WrongTypeException;
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetSequence;
import uk.co.samuelwall.materialtaptargetprompt.extras.StyleBean;
import uk.co.samuelwall.materialtaptargetprompt.extras.backgrounds.FullscreenPromptBackground;
import uk.co.samuelwall.materialtaptargetprompt.extras.backgrounds.RectanglePromptBackground;
import uk.co.samuelwall.materialtaptargetprompt.extras.focals.RectanglePromptFocal;
import uk.co.samuelwall.materialtaptargetprompt.sample.utils.NumUtil;
import uk.co.samuelwall.materialtaptargetprompt.sample.weight.SlidingDrawer.SlidingDrawer;
import uk.co.samuelwall.materialtaptargetprompt.utils.Constants;
import uk.co.samuelwall.materialtaptargetprompt.utils.DensityUtils;

import java.io.IOException;

/**
 * MainAbility
 *
 * @since 2021-06-21
 */
public class MainAbility extends FractionAbility implements Component.ClickedListener {
    private static final int INT_3000 = 3000;
    private SlidingDrawer drawer1;
    private DependentLayout mDlMenu;
    private boolean isOpen = false;
    private MaterialTapTargetPrompt mFabPrompt;
    private ComponentContainer mRootView;
    private ComponentContainer mActionModeView;
    private boolean isMenuShow = false;
    private ResourceManager resManager;
    private Text toast;
    private Text fabToast;
    private boolean isFabToast = false;
    private SupportDialogFragmentExample supportDialogFragmentExample;
    private Component slidingBg;
    private Component selectBg;
    private ScrollView scrollView;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        WindowManager.getInstance().getTopWindow().get().setStatusBarColor(NumUtil.INT_COLOR_STATUS_BAR);
        super.setUIContent(ResourceTable.Layout_ability_main);
        resManager = getResourceManager();
        initViews();
    }

    private void initViews() {
        mRootView = (ComponentContainer) findComponentById(ResourceTable.Id_drawer_layout);
        toast = (Text) findComponentById(ResourceTable.Id_msg_toast);
        fabToast = (Text) findComponentById(ResourceTable.Id_fab_toast);
        scrollView = (ScrollView) findComponentById(ResourceTable.Id_scroll_view);
        findComponentById(ResourceTable.Id_ig_left).setClickedListener(this);
        findComponentById(ResourceTable.Id_ig_dialog).setClickedListener(this);
        mDlMenu = (DependentLayout) findComponentById(ResourceTable.Id_dl_menu);
        selectBg = findComponentById(ResourceTable.Id_select_bg);
        selectBg.setClickedListener(component -> {
            mDlMenu.setScaleX(0);
            selectBg.setVisibility(Component.HIDE);
            isMenuShow = false;
        });
        mDlMenu.setClickedListener(component -> {
            mDlMenu.setScaleX(0);
            selectBg.setVisibility(Component.HIDE);
            isMenuShow = false;
        });
        mDlMenu.setScaleX(0);
        mDlMenu.setPivot(mDlMenu.getWidth(), 0);

        mActionModeView = (ComponentContainer) findComponentById(ResourceTable.Id_actionmode);
        findComponentById(ResourceTable.Id_arrow).setClickedListener(this);
        findComponentById(ResourceTable.Id_ok).setClickedListener(this);

        findComponentById(ResourceTable.Id_btn_navigation_prompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_showOverflowPrompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_showSearchPrompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_button_fab_prompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_showBottomSheetDialogPrompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_showActionModePrompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_showStylePrompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_button_show_for_prompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_showRectPrompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_showFullscreenRectPrompt).setClickedListener(this);
        findComponentById(ResourceTable.Id_button_no_auto_dismiss).setClickedListener(this);
        findComponentById(ResourceTable.Id_other_examples_dialog).setClickedListener(this);
        findComponentById(ResourceTable.Id_other_examples_support_fragment_dialog).setClickedListener(this);
        findComponentById(ResourceTable.Id_other_examples_centre).setClickedListener(this);
        findComponentById(ResourceTable.Id_other_examples_list).setClickedListener(this);
        findComponentById(ResourceTable.Id_other_examples_card).setClickedListener(this);
        findComponentById(ResourceTable.Id_other_sequence).setClickedListener(this);
        findComponentById(ResourceTable.Id_fab).setClickedListener(this);

        slidingBg = findComponentById(ResourceTable.Id_sliding_bg);
        slidingBg.setClickedListener(component -> {
            getMainTaskDispatcher().delayDispatch(() -> {
                slidingBg.setVisibility(Component.HIDE);
                drawer1.setVisibility(Component.HIDE);
                isOpen = false;
            }, NumUtil.INT_100);
        });
        drawer1 = (SlidingDrawer) findComponentById(ResourceTable.Id_slide);
        drawer1.setClickedListener(component -> {
            slidingBg.setVisibility(Component.HIDE);
            drawer1.setVisibility(Component.HIDE);
            isOpen = false;
        });
        drawer1.setOnDrawerCloseListener(() -> {
            drawer1.animateClose();
            slidingBg.setVisibility(Component.HIDE);
            drawer1.setVisibility(Component.HIDE);
            isOpen = false;
        });
        findComponentById(ResourceTable.Id_fab_inSlide).setClickedListener(this);
        findComponentById(ResourceTable.Id_slid_dl).setClickedListener(component -> {
        });
    }

    @Override
    public void onClick(Component component) {
        if (component.getId() != ResourceTable.Id_ig_dialog && isMenuShow) {
            showMenu();
        }
        if (component.getId() != ResourceTable.Id_showActionModePrompt) {
            mActionModeView.setVisibility(Component.HIDE);
        }
        switch (component.getId()) {
            case ResourceTable.Id_ig_left:
                showLeft();
                break;
            case ResourceTable.Id_ig_dialog:
                showMenu();
                break;
            case ResourceTable.Id_arrow:
            case ResourceTable.Id_ok:
                mActionModeView.setVisibility(Component.HIDE);
                break;
            case ResourceTable.Id_ig_search:
                break;
            case ResourceTable.Id_btn_navigation_prompt:
                showSideNavigationPrompt();
                break;
            case ResourceTable.Id_showOverflowPrompt:
                showOverflowPrompt();
                break;
            case ResourceTable.Id_showSearchPrompt:
                showSearchPrompt();
                break;
            case ResourceTable.Id_button_fab_prompt:
                showFabPrompt();
                break;
            case ResourceTable.Id_showBottomSheetDialogPrompt:
                showBottomSheetDialogPrompt();
                break;
            case ResourceTable.Id_showActionModePrompt:
                showActionModePrompt();
                break;
            case ResourceTable.Id_showStylePrompt:
                showStylePrompt();
                break;
            case ResourceTable.Id_button_show_for_prompt:
                showFabPromptFor();
                break;
            case ResourceTable.Id_showRectPrompt:
                showRectPrompt(component);
                break;
            case ResourceTable.Id_showFullscreenRectPrompt:
                showFullscreenRectPrompt(component);
                break;
            case ResourceTable.Id_button_no_auto_dismiss:
                scrollView.setEnabled(false);
                showNoAutoDismiss();
                break;
            case ResourceTable.Id_other_examples_dialog:
                showDialog();
                break;
            case ResourceTable.Id_other_examples_support_fragment_dialog:
                showSupportFragmentDialog();
                break;
            case ResourceTable.Id_other_examples_centre:
                showCentreAbility();
                break;
            case ResourceTable.Id_other_examples_list:
                showListAbility(component);
                break;
            case ResourceTable.Id_other_examples_card:
                showCardsAbility();
                break;
            case ResourceTable.Id_other_sequence:
                showSequence();
                break;
            case ResourceTable.Id_fab:
                scrollView.setEnabled(true);
                showSnackBar();
                break;
            case ResourceTable.Id_fab_inSlide:
                showNavPrompt();
                break;
            default:
                break;
        }
    }

    /**
     * showNavPrompt
     */
    public void showNavPrompt() {
        try {
            new MaterialTapTargetPrompt.Builder(this, mRootView)
                    .setTarget(ResourceTable.Id_fab_inSlide)
                    .setPrimaryText(ResourceTable.String_example_fab_title)
                    .setSecondaryText(ResourceTable.String_example_fab_description)
                    .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                    .setMaxTextWidth(ResourceTable.Float_tap_target_menu_max_width)
                    .show();
        } catch (NotExistException | WrongTypeException | IOException e) {
            e.toString();
        }
    }

    private void showLeft() {
        if (isOpen) {
            drawer1.animateClose();
            slidingBg.setVisibility(Component.HIDE);
            drawer1.setVisibility(Component.HIDE);
            isOpen = false;
        } else {
            slidingBg.setVisibility(Component.VISIBLE);
            drawer1.animateOpen();
            drawer1.setVisibility(Component.VISIBLE);
            isOpen = true;
        }
    }

    private void showMenu() {
        AnimatorProperty animatorProperty = mDlMenu.createAnimatorProperty();
        animatorProperty.setDuration(NumUtil.INT_100);
        if (!animatorProperty.isRunning()) {
            if (isMenuShow) {
                selectBg.setVisibility(Component.HIDE);
                animatorProperty.scaleX(0);
            } else {
                selectBg.setVisibility(Component.VISIBLE);
                animatorProperty.scaleX(1);
            }
            isMenuShow = !isMenuShow;
            animatorProperty.start();
        }
    }

    private void showSnackBar() {
        if (!isFabToast) {
            isFabToast = true;
            AnimatorValue animatorValue = new AnimatorValue();
            animatorValue.setDuration(Constants.NUM_200);
            animatorValue.setStateChangedListener(new Animator.StateChangedListener() {
                @Override
                public void onStart(Animator animator) {
                }

                @Override
                public void onStop(Animator animator) {
                }

                @Override
                public void onCancel(Animator animator) {
                }

                @Override
                public void onEnd(Animator animator) {
                    getMainTaskDispatcher().delayDispatch(() -> {
                        isFabToast = false;
                        fabToast.setHeight(0);
                    }, INT_3000);
                }

                @Override
                public void onPause(Animator animator) {
                }

                @Override
                public void onResume(Animator animator) {
                }
            });
            animatorValue.setValueUpdateListener((animatorValue1, v) ->
                    fabToast.setHeight(DensityUtils.pxToFp(getContext(), NumUtil.INT_56 * v)));
            animatorValue.start();
        }
    }

    /**
     * showSideNavigationPrompt
     */
    public void showSideNavigationPrompt() {
        final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder;
        try {
            tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this, mRootView)
                    .setPrimaryText(ResourceTable.String_menu_prompt_title)
                    .setSecondaryText(ResourceTable.String_menu_prompt_description)
                    .setContentDescription(ResourceTable.String_menu_prompt_content_description)
                    .setFocalPadding(ResourceTable.Float_dp40)
                    .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                    .setMaxTextWidth(ResourceTable.Float_tap_target_menu_max_width)
                    .setTarget(findComponentById(ResourceTable.Id_ig_left))
                    .setIcon(new VectorElement(this, ResourceTable.Graphic_ic_menu));
            tapTargetPromptBuilder.show();
        } catch (NotExistException | IOException | WrongTypeException e) {
            String error = e.toString();
        }
    }

    /**
     * showOverflowPrompt
     */
    public void showOverflowPrompt() {
        final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder;
        try {
            tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this, mRootView)
                    .setPrimaryText(ResourceTable.String_overflow_prompt_title)
                    .setSecondaryText(ResourceTable.String_overflow_prompt_description)
                    .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                    .setMaxTextWidth(ResourceTable.Float_tap_target_menu_max_width)
                    .setTarget(findComponentById(ResourceTable.Id_ig_dialog))
                    .setIcon(new VectorElement(this, ResourceTable.Graphic_ic_more_vert));
            tapTargetPromptBuilder.show();
        } catch (NotExistException | WrongTypeException | IOException e) {
            String error = e.toString();
        }
    }

    /**
     * showSearchPrompt
     */
    public void showSearchPrompt() {
        try {
            new MaterialTapTargetPrompt.Builder(this, mRootView)
                    .setPrimaryText(ResourceTable.String_search_prompt_title)
                    .setSecondaryText(ResourceTable.String_search_prompt_description)
                    .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                    .setMaxTextWidth(ResourceTable.Float_tap_target_menu_max_width)
                    .setIcon(new VectorElement(this, ResourceTable.Graphic_ic_search))
                    .setTarget(ResourceTable.Id_ig_search)
                    .show();
        } catch (NotExistException | WrongTypeException | IOException e) {
            String error = e.toString();
        }
    }

    /**
     * showFabPrompt
     */
    public void showFabPrompt() {
        if (mFabPrompt != null) {
            return;
        }
        try {
            mFabPrompt = new MaterialTapTargetPrompt.Builder(MainAbility.this, mRootView)
                    .setTarget(findComponentById(ResourceTable.Id_fab))
                    .setFocalPadding(ResourceTable.Float_dp40)
                    .setSecondaryText("Tap the envelope to start composing your first email")
                    .setPrimaryText("Send your first email")
                    .setBackButtonDismissEnabled(true)
                    .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                    .setPromptStateChangeListener((prompt, state) -> {
                        if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED
                                || state == MaterialTapTargetPrompt.STATE_NON_FOCAL_PRESSED
                                || state == MaterialTapTargetPrompt.STATE_FOCAL_BACKGROUND_PRESSED) {
                            mFabPrompt = null;
                        }
                    })
                    .create();
        } catch (NotExistException | IOException | WrongTypeException e) {
            String error = e.toString();
        }
        if (mFabPrompt != null) {
            mFabPrompt.show();
        }
    }

    /**
     * showBottomSheetDialogPrompt
     */
    public void showBottomSheetDialogPrompt() {
        final BottomSheetDialogFragmentExample bottomSheetDialogFragmentExample =
                new BottomSheetDialogFragmentExample(this);
        bottomSheetDialogFragmentExample.show();
    }

    /**
     * showActionModePrompt
     */
    public void showActionModePrompt() {
        mActionModeView.setVisibility(Component.VISIBLE);
        try {
            MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(MainAbility.this, mRootView);
            builder.setPrimaryText(ResourceTable.String_action_mode_prompt_title)
                    .setSecondaryText(ResourceTable.String_action_mode_prompt_description)
                    .setFocalPadding(ResourceTable.Float_dp40)
                    .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                    .setMaxTextWidth(ResourceTable.Float_tap_target_menu_max_width)
                    .setTarget(findComponentById(ResourceTable.Id_arrow))
                    .setIcon(new VectorElement(MainAbility.this, ResourceTable.Graphic_ic_arrow))
                    .show();
        } catch (NotExistException | WrongTypeException | IOException e) {
            String error = e.toString();
        }
    }

    /**
     * showStylePrompt
     */
    public void showStylePrompt() {
        StyleBean styleBean = new StyleBean();
        try {
            styleBean.setMttpBackgroundColour(resManager.getElement(
                    ResourceTable.Color_colorAccentPromptBackground).getColor());
            styleBean.setMttpFocalColour(resManager.getElement(ResourceTable.Color_colorPrimary).getColor());
            styleBean.setMttpPrimaryText(resManager.getElement(ResourceTable.String_FabTarget_primaryText).getString());
            styleBean.setMttpSecondaryText(resManager.getElement(
                    ResourceTable.String_FabTarget_secondaryText).getString());
            styleBean.setMttpPrimaryTextColour(resManager.getElement(ResourceTable.Color_green_200).getColor());
            styleBean.setMttpSecondaryTextColour(resManager.getElement(ResourceTable.Color_orange_200).getColor());
            styleBean.setMttpTarget(ResourceTable.Id_fab);
            styleBean.setMttpFocalRadius(resManager.getElement(ResourceTable.Float_vp88).getFloat());
            styleBean.setMttpPrimaryTextSize(resManager.getElement(ResourceTable.Float_fp10).getFloat());
            styleBean.setMttpSecondaryTextSize(resManager.getElement(ResourceTable.Float_fp23).getFloat());
            styleBean.setMttpMaxTextWidth(resManager.getElement(ResourceTable.Float_vp600).getFloat());
            styleBean.setMttpTextPadding(resManager.getElement(ResourceTable.Float_vp81).getFloat());
            styleBean.setMttpFocalToTextPadding(resManager.getElement(ResourceTable.Float_vp8).getFloat());
            styleBean.setMttpTextSeparation(resManager.getElement(ResourceTable.Float_vp0).getFloat());
            styleBean.setMttpPrimaryTextFont(Font.SERIF);
            styleBean.setMttpSecondaryTextFont(Font.MONOSPACE);
            styleBean.setMttpSecondaryTextStyle(StyleBean.FONT_ITALIC);
            styleBean.setMttpIconColourFilter(resManager.getElement(ResourceTable.Color_green_200).getColor());
        } catch (IOException | NotExistException | WrongTypeException e) {
            String error = e.toString();
        }

        final MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(this, mRootView, styleBean);
        builder.setTarget(findComponentById(ResourceTable.Id_ig_dialog))
                .setIcon(new VectorElement(this, ResourceTable.Graphic_ic_more_vert))
                .show();
    }

    /**
     * showFabPromptFor
     */
    public void showFabPromptFor() {
        try {
            new MaterialTapTargetPrompt.Builder(this, mRootView)
                    .setTarget(findComponentById(ResourceTable.Id_fab))
                    .setFocalPadding(ResourceTable.Float_dp40)
                    .setPrimaryText("showFor(7000)")
                    .setSecondaryText("This prompt will show for 7 seconds")
                    .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                    .setPromptStateChangeListener((prompt, state) -> {
                        if (state == MaterialTapTargetPrompt.STATE_SHOW_FOR_TIMEOUT) {
                            toast.setVisibility(Component.VISIBLE);
                            getMainTaskDispatcher().delayDispatch(() ->
                                    toast.setVisibility(Component.HIDE), INT_3000);
                        }
                    })
                    .showFor(NumUtil.INT_7000);
        } catch (NotExistException | WrongTypeException | IOException e) {
            String error = e.toString();
        }
    }

    /**
     * showRectPrompt
     *
     * @param view
     */
    public void showRectPrompt(Component view) {
        new MaterialTapTargetPrompt.Builder(this, mRootView)
                .setTarget(view)
                .setPrimaryText("Different shapes")
                .setSecondaryText("Extend PromptFocal or PromptBackground to change the shapes")
                .setPromptBackground(new RectanglePromptBackground(this))
                .setPromptFocal(new RectanglePromptFocal(this))
                .show();
    }

    /**
     * showFullscreenRectPrompt
     *
     * @param view
     */
    public void showFullscreenRectPrompt(Component view) {
        new MaterialTapTargetPrompt.Builder(this, mRootView)
                .setTarget(view)
                .setPrimaryText("Different shapes")
                .setSecondaryText("Extend PromptFocal or PromptBackground to change the shapes")
                .setPromptBackground(new FullscreenPromptBackground(this))
                .setPromptFocal(new RectanglePromptFocal(this))
                .show();
    }

    /**
     * showNoAutoDismiss
     */
    public void showNoAutoDismiss() {
        if (mFabPrompt != null) {
            return;
        }
        mFabPrompt = new MaterialTapTargetPrompt.Builder(this, mRootView)
                .setTarget(findComponentById(ResourceTable.Id_fab))
                .setPrimaryText("No Auto Dismiss")
                .setSecondaryText("This prompt will only be removed after tapping the envelop")
                .setAnimationCurveType(Animator.CurveType.ACCELERATE_DECELERATE)
                .setAutoDismiss(false)
                .setAutoFinish(false)
                .setCaptureTouchEventOutsidePrompt(true)
                .setPromptStateChangeListener((prompt, state) -> {
                    if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED) {
                        prompt.finish();
                        mFabPrompt = null;
                    } else if (state == MaterialTapTargetPrompt.STATE_NON_FOCAL_PRESSED
                            || state == MaterialTapTargetPrompt.STATE_FOCAL_BACKGROUND_PRESSED) {
                        mFabPrompt = null;
                    }
                })
                .show();
    }

    /**
     * showDialog
     */
    public void showDialog() {
        DialogStyleAbility dialogStyleAbility = new DialogStyleAbility(this);
        dialogStyleAbility.show();
    }

    /**
     * showSupportFragmentDialog
     */
    public void showSupportFragmentDialog() {
        supportDialogFragmentExample = new SupportDialogFragmentExample();
        supportDialogFragmentExample.setAbility(MainAbility.this);
        getFractionManager()
                .startFractionScheduler()
                .replace(ResourceTable.Id_container, supportDialogFragmentExample)
                .submit();
    }

    /**
     * showCentreAbility
     */
    public void showCentreAbility() {
        nextPage(CentrePositionAbility.class);
    }

    /**
     * showCardsAbility
     */
    public void showCardsAbility() {
        nextPage(CardAbility.class);
    }

    /**
     * showSequence
     */
    public void showSequence() {
        try {
            new MaterialTapTargetSequence()
                    .addPrompt(new MaterialTapTargetPrompt.Builder(this, mRootView)
                            .setTarget(findComponentById(ResourceTable.Id_fab))
                            .setPrimaryText("Step 1")
                            .setSecondaryText("This will show for 4 seconds")
                            .setFocalPadding(ResourceTable.Float_dp40)
                            .create(), NumUtil.INT_7000)
                    .addPrompt(new MaterialTapTargetPrompt.Builder(this, mRootView)
                            .setTarget(findComponentById(ResourceTable.Id_ig_search))
                            .setPrimaryText("Step 2")
                            .setSecondaryText("This will show till you press it")
                            .setAnimationCurveType(Animator.CurveType.LINEAR)
                            .setFocalPadding(ResourceTable.Float_dp40)
                            .setIcon(new VectorElement(this, ResourceTable.Graphic_ic_search)))
                    .show();
        } catch (NotExistException | IOException | WrongTypeException e) {
            String error = e.toString();
        }
    }

    /**
     * showListAbility
     *
     * @param view
     */
    public void showListAbility(Component view) {
        nextPage(ListAbility.class);
    }

    /**
     * nextPage
     *
     * @param pageName
     */
    public void nextPage(Class pageName) {
        Intent secondIntent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(MainAbility.this.getBundleName())
                .withAbilityName(pageName.getName())
                .build();
        secondIntent.setOperation(operation);
        startAbility(secondIntent);
    }

    /**
     * hideFraction
     */
    public void hideFraction() {
        getFractionManager()
                .startFractionScheduler()
                .remove(supportDialogFragmentExample)
                .submit();
    }
}
